/**
 * Created by pan on 2018年02月07日14:25:32.
 * @link 小说目录
 */
const express = require('express');
const router = express.Router();
const superagent = require('superagent');

const fetchData = id => {
    return new Promise(resolve => {
        resolve(
            superagent.get(
                `https://api04ssfv.zhuishushenqi.com/btoc/${id}?view=chapters&platform=ios&t=1548862684609`
            )
        );
    });
};

router.get('/', async function(req, res, next) {
    if (req.query.sourceId) {
        const data = await fetchData(req.query.sourceId);
        res.json({ result: 1, data: data.body });
    } else {
        res.send({
            result: 0,
            msg: '参数错误',
        });
    }
});

module.exports = router;
